package storage.buffer;

import java.lang.reflect.Constructor;

import config.Config;


public class BufferManagerFactory {
	private static AbstractBufferManager bufferManager = null;
	private static String packageName = BufferManagerFactory.class.getPackage().getName();
	
	public static AbstractBufferManager getBufferManager() {
		if (bufferManager == null) {
			String managerName = packageName + "." +
				Config.getString("bufferManager", "LRUBufferManager");

			try {
				@SuppressWarnings("unchecked")
				Class<AbstractBufferManager> managerClass = (Class<AbstractBufferManager>) Class.forName(managerName);
				Constructor<AbstractBufferManager> cons = managerClass.getConstructor(new Class[] {});
				bufferManager = (AbstractBufferManager) cons.newInstance(new Object[] {});
			} catch (Exception e) {
				e.printStackTrace(System.err);
			}
		}
		
		return bufferManager;
	}
}
